<?php

namespace App\Admin\Actions\Grid;

use App\Models\Posts\WxPost;
use App\Models\Posts\WxPostsImg;
use App\Models\WxNotice;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class PostPassAction extends BatchAction
{
    /**
     * @return string
     */
	protected $title = '审核通过';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        $id = $this->getKey();
        $uid = WxPost::where('id',$id)->value('user_id');
        // 发送通知
        (new WxNotice())->addNotice($uid,'帖子审核通知','审核通过，您的发表的帖子已经审核通过',0);
        WxPost::where('id',$id)->update(['is_examine'=>1]);
        return $this->response()
            ->success('操作成功'.json_encode($this->getKey()))
            ->refresh();
    }

    /**
	 * @return string|array|void
	 */
	public function confirm()
	{
		 return ['确认审核通过?'];
	}

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [];
    }
}
